#!/usr/bin/perl -w
use strict;
use File::Spec;
use Getopt::Long;
my %compress = ( 'bz2' => 'bzcat',
		 'gz'  => 'zcat');
my $tdir = '/tmp/tophat';
my $dir = '.';
my $gff = '/project/neurospora/RNA-Seq/neurospora_crassa_OR74A_7.NCBI_PASA_allnames.gff3';
GetOptions(
	   'd|dir:s'  => \$dir,
	   't|tdir:s' => \$tdir,
	   );
mkdir($tdir) unless -d $tdir;

my $tophat = 'tophat --microexon-search --butterfly-search -I 1000 -m 1 --coverage-search --closure-search -G neurospora_crassa_OR74A_7.NCBI_PASA_allnames.gff3 --solexa-quals -p 10 ';
opendir(DIR, $dir ) || die "$!";

for my $file ( readdir(DIR) ) {    
    next unless( $file =~ /((\S+)\.fastq)(\.(\S+))?$/ );
    my ($stem,$twig,$ext) = ($1,$2,$4);
    my $working = "$dir/$file";
    if( $ext ) {
	$working = "/tmp/$stem";
	warn "zcat $dir/$file > $working\n";
	`zcat $dir/$file > $working`;
    } 
    warn "$tophat -o $tdir/$twig neurospora_crassa_OR74A_7 $working\n";
    `$tophat -o $tdir/$twig neurospora_crassa_OR74A_7 $working`;
}
